package com.lobstar.xrpc.common;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.lobstar.xrpc.common.po.Task;
import com.lobstar.xrpc.service.base.ServiceInvoker;

abstract public class TaskExecutable {

	protected ExecutorService taskProcessor;
	protected ServiceInvoker invoker;
	protected ResponseHandler responseHandler;

	public TaskExecutable(String basePackage,int taskExecutorSize,int responseCacheSize,int responseCacheExpire) {
		this.responseHandler = ResponseHandler.build(responseCacheSize,responseCacheExpire);
		this.invoker = ServiceInvoker.buildInvoker(basePackage);
		this.taskProcessor = Executors.newFixedThreadPool(taskExecutorSize);
	}

	public void cacheTask(String id,Task task) {
		responseHandler.cache(id, task);
	}
	public ExecutorService getTaskProcessor() {
		return taskProcessor;
	}

	public void setTaskProcessor(ExecutorService taskProcessor) {
		this.taskProcessor = taskProcessor;
	}

	public ServiceInvoker getInvoker() {
		return invoker;
	}

	public void setInvoker(ServiceInvoker invoker) {
		this.invoker = invoker;
	}

	public ResponseHandler getResponseHandler() {
		return responseHandler;
	}

	public void setResponseHandler(ResponseHandler responseHandler) {
		this.responseHandler = responseHandler;
	}


}
